//
//  HallCell.m
//  OrderSeat
//
//  Created by haiming on 13-10-11.
//  Copyright (c) 2013年 wangwei. All rights reserved.
//

#import "HallCell.h"

#define ORDER_IMAGE [UIImage imageNamed:@"bookingbox_btn4_n.png"]
#define SELECTED_IMAGE [UIImage imageNamed:@"bookingbox_btn3_n.png"]
#define NORMAL_IMAGE [UIImage imageNamed:@"bookingbox_btn2_n.png"]


@implementation HallCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setContent:(NSMutableDictionary*)dic
{
    self.dictionary = dic;
    
    self.seatNameLabel.text = [dic objectForKey:@"zwname"];
    self.peopleNumLabel.text = [[dic objectForKey:@"renshu"] stringValue];
    
    if([[_dictionary objectForKey:@"zhuangtai"] intValue] == 2) {
        [_orderBtn setBackgroundImage:ORDER_IMAGE forState:UIControlStateNormal];
    }
    else if([[_dictionary objectForKey:@"selected"] intValue] == 1) {
        [_orderBtn setBackgroundImage:SELECTED_IMAGE forState:UIControlStateNormal];
    }
    
    else if([[_dictionary objectForKey:@"selected"] intValue] == 0){
        [_orderBtn setBackgroundImage:NORMAL_IMAGE forState:UIControlStateNormal];
    }
    
    [self reLayoutSubviews];
}

- (void)reLayoutSubviews
{
    [_view drawBorder];
    
    [self.peopleNumLabel autoWidthForSingleLine];
    self.peopleNumRightLabel.left = self.peopleNumLabel.right_1;
}

- (IBAction)orderAction:(id)sender
{
    if([[_dictionary objectForKey:@"zhuangtai"] intValue] == 2) return;
    
    NSString *selected = [_dictionary objectForKey:@"selected"];
    selected = [selected isEqualToString:@"0"] ? @"1" : @"0";
    
    [_dictionary setObject:selected forKey:@"selected"];
    
    if ([selected intValue] == 1) {
        [_orderBtn setBackgroundImage:SELECTED_IMAGE forState:UIControlStateNormal];
    }else {
        [_orderBtn setBackgroundImage:NORMAL_IMAGE forState:UIControlStateNormal];
    }
    
    if (_delegate) {
        [_delegate selectedFinished];
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}

@end
